<template>
<<<<<<< HEAD
  <div class='container'>学科管理</div>
</template>

<script>
export default {}
=======

  <!-- 第一页  每页必用 -->
  <div class="dashboard-container">
    <div class="xk-container">
      <el-card shadow="never">
        <div>
          <span class="textname">学科名称</span>
          <el-input style="width: 200px" size="small" class="filter-input" v-model="queryInfo.subjectName" @clear="getList"> </el-input>
          <el-button class="filter-item" size="small" @click="queryInfo.subjectName = ''">{{ $t('table.clear') }}</el-button>
          <el-button class="filter-item" size="small" type="primary" @click="getList">{{ $t('table.search') }}</el-button>
          <el-button class="filter-item fr" size="small" style="margin-left: 10px" @click="addDialog = true" type="success" icon="el-icon-edit">{{ $t('table.xzxk') }}</el-button>
        </div>
        <!-- 灰色提示 -->
        <div>
          <el-alert :title="alertText" type="info" show-icon :closable="false" class="alert"> </el-alert>
        </div>
        <!-- list表格 -->
        <el-table :key="id" :data="list" style="width: 100%">
          <el-table-column rowspan="1" prop="id" type="index" label="编号" width="50"> </el-table-column>
          <el-table-column rowspan="1" prop="subjectName" label="学科名称" width="130"> </el-table-column>
          <el-table-column rowspan="1" prop="username" label="创建者" width="160"> </el-table-column>
          <el-table-column rowspan="1" label="创建日期" width="200">
            <template slot-scope="scope">
              {{ scope.row.addDate | parseTimeByString }}
            </template>
          </el-table-column>
          <el-table-column rowspan="1" label="前台是否显示" width="160">
            <template slot-scope="scope">
              {{ scope.row.isFrontDisplay ? '是' : '否' }}
            </template>
          </el-table-column>
          <el-table-column rowspan="1" prop="twoLevelDirectory" label="二级目录" width="130"> </el-table-column>
          <el-table-column rowspan="1" prop="tags" label="标签" width="130"> </el-table-column>
          <el-table-column rowspan="1" prop="totals" label="题目数量" width="130"> </el-table-column>
          <el-table-column width="240" prop="address" label="操作">
            <template slot-scope="scope">
              <el-button type="text" @click="toCatagory(scope.row)"><span>学科分类</span></el-button>
              <el-button type="text" @click="totags(scope.row)"><span>学科标签</span></el-button>
              <el-button type="text" @click="handle(scope.row)"><span>修改</span></el-button>
              <el-button type="text" @click="deleteID(scope.row.id)"><span>删除</span></el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="block">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="queryInfo.page"
            :page-sizes="[5, 10, 20, 30]"
            :page-size="queryInfo.pagesize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
          >
          </el-pagination>
        </div>
      </el-card>
    </div>
    <!-- -------------------------------------------------弹出页面-------------------------------------- -->
    <!-- 添加用户输入框弹出 -->
    <el-dialog title="新增学科" :visible.sync="addDialog" width="25%">
      <!-- 内容主体 -->
      <el-form :model="addFrom" :rules="addFromrules" label-width="100px">
        <el-form-item label="用户名称" prop="subjectName">
          <el-input v-model="addFrom.subjectName" placeholder="请输入学科"></el-input>
        </el-form-item>

        <el-form-item label="是否显示">
          <el-switch v-model="addFrom.isFrontDisplay" active-color="#13ce66" inactive-color="#ff4949"> </el-switch>
        </el-form-item>
      </el-form>
      <span slot="footer">
        <el-button @click="addDialog = false">取 消</el-button>
        <el-button type="primary" @click="addUser">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 修改修改用户输入框弹出 -->
    <el-dialog title="修改学科" :visible.sync="updateDialog" width="25%">
      <!-- 内容主体 -->
      <el-form :model="updateFrom" :rules="updateFromrules" label-width="100px">
        <el-form-item label="用户名称" prop="subjectName">
          <el-input v-model.trim="updateFrom.subjectName"></el-input>
        </el-form-item>

        <el-form-item label="是否显示">
          <el-switch v-model="updateFrom.isFrontDisplay" active-color="#13ce66" inactive-color="#ff4949"> </el-switch>
        </el-form-item>
      </el-form>
      <span slot="footer">
        <el-button @click="updateDialog = false">取 消</el-button>
        <el-button type="primary" @click="updateUser">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 弹框 学科分类页面-->
  </div>
</template>

<script>
import { list, add, update, remove } from '@/api/hmmm/subjects'
import directorys from './directorys'
import tags from './tags'
export default {
  name: 'aaaa',
  components: {
    directorys,
    tags
  },
  props: {},
  data() {
    return {
      id: 0,
      queryInfo: {
        subjectName: '',
        // 当前页数
        page: 1,
        // 当前每页几条
        pagesize: 5
      },
      list: [],
      // 当前多少数据
      total: 0,
      // 灰色一共多少数据
      alertText: '',

      // 添加对话框后隐藏
      addDialog: false,
      addFrom: {
        subjectName: '',
        isFrontDisplay: true
      },
      // 修改对话框里的东西
      updateFrom: {
        id: null,
        subjectName: '',
        isFrontDisplay: null
      },
      // 表单添加验证
      addFromrules: {
        subjectName: [{ required: true, message: '请输入用户名', trigger: 'blur' }]
      },
      // 表单修改验证
      updateFromrules: {
        subjectName: [{ required: true, message: '请输入用户名', trigger: 'blur' }]
      },
      // 小开关按钮
      value: true,
      // 修改对话框隐藏
      updateDialog: false
    }
  },
  created() {
    // 表单渲染
    this.getList()
  },
  methods: {
    // 表单渲染
    getList() {
      list(this.queryInfo)
        .then((data) => {
          this.list = data.data.items
          this.total = data.data.counts
          this.alertText = `数据一共有${this.total}条`
        })
        .catch((e) => {
          this.$message('da')
        })
    },
    handleSizeChange(val) {
      this.queryInfo.pagesize = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.queryInfo.page = val
      this.getList()
    },
    // 添加学科
    addUser() {
      add({
        subjectName: this.addFrom.subjectName,
        isFrontDisplay: this.addFrom.isFrontDisplay
      })
        .then((data) => {
          this.$message.success('添加学科成功')
          this.getList()
          this.addFrom.subjectName = ''
        })
        .catch((e) => {
          this.$message('添加学科失败')
        })
      this.addDialog = false
    },
    // 修改学科
    updateUser() {
      update(this.updateFrom)
        .then((e) => {
          this.$message.success('修改学科成功')
          this.getList()
        })
        .catch((e) => {
          this.$message('修改学科失败')
        })
      this.updateDialog = false
    },
    handle(val) {
      this.updateDialog = true
      // this.updateFrom = JSON.parse(JSON.stringify(val))
      this.updateFrom.id = val.id
      this.updateFrom.subjectName = val.subjectName
      this.updateFrom.isFrontDisplay = val.isFrontDisplay ? true : false
    },
    // 删除学科
    deleteID(id) {
      console.log(id)
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async () => {
          const res = await remove({ id })
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
          this.getList()
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
    // 跳转页面
      toCatagory(val){
      this.$store.state.type=true
      this.$router.push({
          path:'/subjects/directorys/:subjectId',
          query:{
            id:val.id,
           data:val.subjectName
          
        }
      })
    },
      totags(val){
      this.$store.state.type=true
      this.$router.push({
          path:'/subjects/tags/:subjectId',
          query:{
            id:val.id,
           data:val.subjectName
        }
      })
    }
  }
}
>>>>>>> 99b581ad90efc8af6413e4097d13ec8f4855db58
</script>

<style scoped lang='less'></style>
